/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.bean;

import com.aal.entity.Customer;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author v
 */
@Stateless
public class CustomerFacade extends AbstractFacade<Customer> implements CustomerFacadeLocal {
    @PersistenceContext(unitName = "AAL-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CustomerFacade() {
        super(Customer.class);
    }
    public List<Customer> findUser(String username) {
        Query query = em.createNamedQuery("Customer.findByUsername");
              query.setParameter("username",'%'+username+'%');
        return query.getResultList();
    }
    public Customer loginOk(String username,String password){
        Query query = em.createNamedQuery("Customer.loginOK");
              query.setParameter("username", username);
              query.setParameter("password", password);
        return (Customer) query.getSingleResult();
    }
    
}
